package com.wondertek.common.util.base;

import cn.hutool.extra.spring.SpringUtil;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

/**
 * @author: gongjiangtao
 * @date: 2024/8/3 0:18
 * @Description: i18n国际化工具类
 * @Version: 1.0
 */
public class MessageUtils {

    private static final MessageSource MESSAGE_SOURCE = SpringUtil.getBean(MessageSource.class);

    public static String getMessage(String key) {
        try {
            return MESSAGE_SOURCE.getMessage(key, null, LocaleContextHolder.getLocale());
        } catch (Exception e) {
            return key;
        }
    }
}
